package com.example.news.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

import com.example.news.sqlite.SQLiteHelper;
public class LoginDao {
    private SQLiteHelper sqLiteHelper;
    private SQLiteDatabase db ;
    public LoginDao(Context context){
        sqLiteHelper = new SQLiteHelper(context);
    }
    /*登陆功能*/
    public boolean login(String username , String pwd){
        // 当数据库中的数据进行查询操作的时候，需要调用getReadableDatabase()
        db = sqLiteHelper.getReadableDatabase();
        Cursor cursor = db.query("login", new String[]{"username"},"username = ? and pwd = ?",new String[]{username,pwd}, null,null,null);
        if (cursor.moveToNext()){
            cursor.close();
            db.close();
            return true;
        }else {
            return false;
        }
    }
    //登记功能
    public boolean register(String username,String pwd){
    db=sqLiteHelper.getReadableDatabase();
    db.execSQL("insert into login values('"+username+"','"+pwd+"')");
        db.close();
    return true;
    }
}
